/**
 * 
 */
package base.io;



/**
 * <DL><DT>标题</DT></DL>
 *
 * @author liuboen
 * 
 * @since 2012-7-18
 * @version 1.0.0
 */
public class FTPTransfer {
	static{
		System.setProperty("java.net.preferIPv4Stack", "true");
	}
	  public static void main(String[] args) { 
	/*		FTPClient client = new FTPClient();
			// 设置编码
			client.setCharset("UTF-8");
			// 设置传输类型 为二进制
			client.setType(FTPClient.TYPE_BINARY);
			// 建立连接
			try {
				client.connect("192.168.16.116", 21);			
				// 登陆
				client.login("hao32", "hao32");
				client.download("test.txt", new File("D:/test-116.txt"));
				client.disconnect(true);
			} catch (IllegalStateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (FTPIllegalReplyException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (FTPException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (FTPDataTransferException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (FTPAbortedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}*/
	    } 
/*
	*//**
	 * FTP上传单个文件测试
	 *//*
	public static void testUpload() {
		FTPClient ftpClient = new FTPClient();
		FileInputStream fis = null;

		try {
			ftpClient.connect("192.168.14.117");
			ftpClient.login("admin", "123");

			File srcFile = new File("C:\\new.gif");
			fis = new FileInputStream(srcFile);
			// 设置上传目录
			ftpClient.changeWorkingDirectory("/admin/pic");
			ftpClient.setBufferSize(1024);
			ftpClient.setControlEncoding("GBK");
			// 设置文件类型（二进制）
			ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
			ftpClient.storeFile("3.gif", fis);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("FTP客户端出错！", e);
		} finally {
			IOUtils.closeQuietly(fis);
			try {
				ftpClient.disconnect();
			} catch (IOException e) {
				e.printStackTrace();
				throw new RuntimeException("关闭FTP连接发生异常！", e);
			}
		}
	}

	*//**
	 * FTP下载单个文件测试
	 *//*
	public static void testDownload() {
		FTPClient ftpClient = new FTPClient();
		FileOutputStream fos = null;

		try {
			ftpClient.connect("192.168.16.116");
			ftpClient.login("root", "denong1234");

			String remoteFileName = "/home/denong/fds";
			fos = new FileOutputStream("d:/fds.txt");

			ftpClient.setBufferSize(1024);
			// 设置文件类型（二进制）
			ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
			ftpClient.retrieveFile(remoteFileName, fos);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("FTP客户端出错！", e);
		} finally {
			IOUtils.closeQuietly(fos);
			try {
				ftpClient.disconnect();
			} catch (IOException e) {
				e.printStackTrace();
				throw new RuntimeException("关闭FTP连接发生异常！", e);
			}
		}
	}
	
	public static void F(){
		FTPClient ftp = new FTPClient();
		 boolean error = false;
		    try {
		      int reply;
		      ftp.connect("ftp.foobar.com");
		      //System.out.println("Connected to " + server + ".");
		      System.out.print(ftp.getReplyString());

		      // After connection attempt, you should check the reply code to verify
		      // success.
		      reply = ftp.getReplyCode();

		      if(!FTPReply.isPositiveCompletion(reply)) {
		        ftp.disconnect();
		        System.err.println("FTP server refused connection.");
		        System.exit(1);
		      }
		       // transfer files
		      ftp.logout();
		    } catch(IOException e) {
		      error = true;
		      e.printStackTrace();
		    } finally {
		      if(ftp.isConnected()) {
		        try {
		          ftp.disconnect();
		        } catch(IOException ioe) {
		          // do nothing
		        }
		      }
		      System.exit(error ? 1 : 0);
		    }

	}*/
}
